package com.example.logisticsingle.dto;


import com.example.logisticsingle.constants.ResponseEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;



@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 3015310910791633479L;

    /**
     * 响应状态：成功（true）、失败（false）
     */
    private boolean status;
    /**
     * 结果状态码
     */
    private String code;
    /**
     * 消息描述
     */
    private String message;
    /**
     * 实体数据
     */
    //@JsonInclude(value = JsonInclude.Include.NON_NULL)
    private T data;

    public Result(ResponseEnum responseEnum){
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
    }

    public Result(ResponseEnum responseEnum,boolean isSuccess){
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
        this.status = isSuccess;
    }

    public Result(ResponseEnum responseEnum,boolean isSuccess,T date){
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
        this.status = isSuccess;
        this.data = date;
    }

    public Result(String code, String message,boolean status) {
        this.code = code;
        this.message = message;
        this.status = status;
    }

    @Override
    public String toString() {
        return "Result{" +
                "status=" + status +
                ", code='" + code + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }


}
